package chezsmithybot;

import com.google.wave.api.*;
import java.util.logging.Logger;
import java.util.List;

@SuppressWarnings("serial")
public class ChezsmithybotServlet extends AbstractRobotServlet {
	
	private static final Logger log = Logger
    .getLogger(ChezsmithybotServlet.class.getName());

	@Override
  	public void processEvents(RobotMessageBundle bundle) {
	    Wavelet wavelet = bundle.getWavelet();
	    CommandEngine ce = new CommandEngine();
	            
	    for (Event e: bundle.getEvents()) {
	    	
	    	switch(e.getType()) {
	    		case WAVELET_PARTICIPANTS_CHANGED:
	    			if (wavelet.getParticipants().size() < 2) {
	    				ce.commandParser(e,wavelet,"/delete");
	    			} else {
	    				ce.commandParser(e,wavelet,"/addwave");
	    			}
	        		break;
	    		case BLIP_SUBMITTED:
	    			if (!(e.getModifiedBy().equalsIgnoreCase("chezsmithy-bot@appspot.com"))) {
	    				String blipText = e.getBlip().getDocument().getText();
	    				
	    				if (blipText.contains("/")) {
	    					// Enter Command Mode
	    					ce.commandParser(e,wavelet,blipText);
	    				}
	    			}
	    			break;
				default:
					break;
	    	}
	    }
	    
	}

	
}